import Router from '@koa/router'
import { OpenApiGeneratorV3 } from '@asteasolutions/zod-to-openapi'

import { registryAuth } from '../controllers/auth.js'
import { registryData } from '../controllers/data.js'

const generator = new OpenApiGeneratorV3([...registryAuth.definitions, ...registryData.definitions])

const swaggerSpec = generator.generateDocument({
  openapi: '3.0.0',
  info: {
    title: 'TRF to GPO',
    version: '0.1.0'
  },
})

const router = new Router()

router.get('/swagger.json', async (ctx) => {
  ctx.set('Content-Type', 'application/json')
  ctx.body = swaggerSpec
})

export default router